#pragma once

namespace Serialize_xml
{

	class XMLSerialize;

	class UserTypeXml
	{
	public:
		virtual void serialize(XMLSerialize &obj, const char *name) const = 0;
		virtual bool deserialize(XMLSerialize &obj) = 0;
	};

#define SERIALIZE_XML(...)                                    \
	void serialize(XMLSerialize &obj, const char *name) const \
	{                                                         \
		XMLElement *newNode = obj.doc.NewElement(name);       \
		obj.pos->InsertEndChild(newNode);                     \
		XMLElement *pre = obj.pos;                            \
		obj.pos = newNode;                                    \
		obj.write_args(__VA_ARGS__);                          \
		obj.pos = pre;                                        \
	}                                                         \
                                                              \
	bool deserialize(XMLSerialize &obj)                       \
	{                                                         \
		XMLElement *pre = obj.pos;                            \
		obj.pos = pre->FirstChildElement("mem");              \
		if (obj.pos == NULL)                                  \
		{                                                     \
			return false;                                     \
		}                                                     \
		obj.read_args(__VA_ARGS__);                           \
		obj.pos = pre;                                        \
		return true;                                          \
	}

}